package com.baomidou.ant.service.impl;

import com.baomidou.ant.entity.QuestionInfo;
import com.baomidou.ant.mapper.QuestionInfoMapper;
import com.baomidou.ant.service.IQuestionInfoService;
import com.baomidou.ant.utils.MyStringUtils;
import com.baomidou.ant.vo.Request.RequestQuestionListVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jobob
 * @since 2021-03-24
 */
@Service
public class QuestionInfoServiceImpl extends ServiceImpl<QuestionInfoMapper, QuestionInfo> implements IQuestionInfoService {


    @Override
    public IPage<QuestionInfo> questionList(RequestQuestionListVo requestQuestionListVo) {
        IPage<QuestionInfo> infoIPage=new Page<>(requestQuestionListVo.getDisplayStart(),requestQuestionListVo.getDisplayLength());
        QueryWrapper<QuestionInfo> queryWrapper=new QueryWrapper<>();
        if(StringUtils.isNotEmpty(requestQuestionListVo.getQuestionType())){
            queryWrapper.like("question_type",requestQuestionListVo.getQuestionType());
        }
        if(StringUtils.isNotEmpty(requestQuestionListVo.getQuestionLevel())){
            queryWrapper.eq("question_level",requestQuestionListVo.getQuestionLevel());
        }
        if(StringUtils.isNotEmpty(requestQuestionListVo.getQuestionTitle())){
            queryWrapper.like("question_title",requestQuestionListVo.getQuestionTitle());
        }

        IPage<QuestionInfo> questionInfoIPage=page(infoIPage,queryWrapper);
        if(questionInfoIPage.getRecords().size()<=0){
            return null;
        }
        return questionInfoIPage.convert(questionInfo -> {
            QuestionInfo info=new QuestionInfo();
            BeanUtils.copyProperties(questionInfo,info);
            return info;
        });
    }

}
